package com.meixiang.activity.account.myShopper;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.adapter.personalCenter.OrderLogisticsAdapter;
import com.meixiang.entity.JsonBean;
import com.meixiang.entity.myOrder.OrderLogistics;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbJsonUtil;
import com.meixiang.util.AbStrUtil;
import com.meixiang.util.VirtualDataHelper;

import org.json.JSONObject;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author yinsujun  Created at 2016/5/9 17:46
 *         订单查看物流状态
 */
public class OrderForCheckLogisticsActivity extends BaseActivity {
//    @Bind(R.id.order_logistics_tv_company_name)
    TextView tvCompanyName;
//    @Bind(R.id.order_logistics_tv_company_telephone)
    TextView tvCompanyTelephone;
//    @Bind(R.id.order_logistics_tv_order_no)
    TextView tvOrderNo;
    @Bind(R.id.order_logistics_recycler_view)
    RecyclerView mRecyclerView;
    private OrderLogisticsAdapter mAdapter;
    private String orderId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_for_check_logistics);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        setTitle("查看物流");
    }

    @Override
    protected void initView() {
        orderId=getIntent().getStringExtra("orderId");
        mAdapter=new OrderLogisticsAdapter(context);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
        View headView= LayoutInflater.from(context).inflate(R.layout.activity_order_check_logistics_header,mRecyclerView,false);
        mAdapter.setHeaderView(headView);

        tvCompanyName= (TextView) mAdapter.getHeaderView().findViewById(R.id.order_logistics_tv_company_name);
        tvCompanyTelephone= (TextView) mAdapter.getHeaderView().findViewById(R.id.order_logistics_tv_company_telephone);
        tvOrderNo= (TextView) mAdapter.getHeaderView().findViewById(R.id.order_logistics_tv_order_no);
    }

    @Override
    protected void setData() {
        getData();

    }
    private void getData(){
        String url= Config.CHECK_ORDER_LOGISTICS;
        HttpParams params=new HttpParams();
        if(!AbStrUtil.isEmpty(orderId)){
            params.put("orderId",orderId);
        }
        HttpUtils.post(url, params, new HttpCallBack(this) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                OrderLogistics orderLogistics= AbJsonUtil.fromJson(result.optJSONObject("order").toString(),OrderLogistics.class);
                setLogisticsInfo(orderLogistics);
                if(orderLogistics!=null){
                    mAdapter.addLogistics(orderLogistics);
                }
            }

            @Override
            public void onError(String code, String message) {
                Tool.showTextToast(context,message);

            }
        });

    }
    private void setLogisticsInfo(OrderLogistics orderLogistics){
        tvCompanyName.setText(orderLogistics.getLogisticsCompany());
        tvCompanyTelephone.setText(orderLogistics.getLogisticsPhone());
        tvOrderNo.setText(orderLogistics.getShippingCode());

    }
    @Override
    public void onClick(View v) {

    }
}
